<?php
class Controller_Test extends Controller 
{
	public function __construct($req, $res) {
		parent::__construct($req, $res);
	}

    public function action_initcppa()
    {
        //首先是合并表
//        CPPA_Init::merge_cppa_report();
//        CPPA_Init::merge_cppa_report_detail();
        //第二步初始化daily表
        CPPA_Init::initDaily();
        //第三步初始化stats表
        CPPA_Init::initStats();
        echo "OK";
    }

    public function action_cache()
    {
        $cache = Cache::instance('memcache');
        echo $cache->get('hello');
    }
    public function action_activity_create()
    {
        $project = '推广活动测试: 应用汇推广活动';
        $price   = '1.50';
        $pkgname = 'com.appchina.yyh';
        $pay_type = 'CPA';
        $pay_by   = 'newbie';
        $ratio    = '0.90';

        $activity_id = TuiGuang_Activity::create_app_project($project, $price, $pkgname, $pay_type, $pay_by, $ratio);
        echo $activity_id;
    }

    public function action_activity_info()
    {
        $info = TuiGuang_Activity::info(1);
        print_r($info);
    }

    public function action_activity_verify($activity_id)
    {
        $act = new TuiGuang_Activity($activity_id);
        $result = $act->verify();
        print_r($result);
    }

    public function action_channel_add ()
    {
        $name = '测试渠道C';
        $key  = 'test.chn.0xC';
        $desc = 'hello,world';
        $merid = 1;
        $id = TuiGuang_Channel::add($name, $key, $desc, $merid);
        echo $id;
    }

    public function action_channel_info ($channel_id)
    {
        $info = TuiGuang_Channel::info($channel_id);
        print_r($info);
    }

    public function action_tuiguang_has ($activity_id, $channel_id)
    {
        var_dump(TuiGuang::has_channel($activity_id, $channel_id));
    }

    public function action_tuiguang_add ($activity_id, $channel_id)
    {
        var_dump(TuiGuang::add_2_activity($activity_id, $channel_id));
    }

    public function action_tuiguang_verify ($activity_id, $channel_id)
    {
        $tg = new TuiGuang($activity_id, $channel_id);
        $target_url = 'http://www.sssss';
        var_dump($tg->verify($target_url));
    }

    public function action_tuiguang_close ($activity_id, $channel_id)
    {
        $tg = new TuiGuang($activity_id, $channel_id);
        $target_url = 'http://www.sssss';
        var_dump($tg->close());
    }

    public function action_import ()
    {
        $tool = new TuiGuang_Effect_Import;
        $tool->import('2012-12-18');
        $tool->import();
    }

    public function action_budget_build()
    {
        $budget = new Estimate_Budget;
        $month  = '2012-12';
        $start_day = '2012-12-01';
        $stop_day  = '2012-12-31';
        $budget->build($month, $start_day, $stop_day);
    }

    public function action_budget_project_confirm($budget_id, $ratio = NULL)
    {
        $budget = new Estimate_Budget($budget_id);
        $budget->confirm_by_project($ratio);
    }

    public function action_budget_business_confirm($budget_id, $ratio = NULL)
    {
        $budget = new Estimate_Budget($budget_id);
        $budget->confirm_by_business($ratio);
    }


    public function action_financial_build ()
    {
        $merchant_id = 1;
        $activity_id = 1;
        $activity_pay_type = 'CPA';
        $activity_pay_param = 'newbie';
        $pay_by_count = 150;
        $pay_by_money = 22500;
        $pay_no       = '2012-12';

        $rs = Estimate_Financial::build($merchant_id, $activity_id, $activity_pay_type, $activity_pay_param, $pay_by_count, $pay_by_money, $pay_no);
        var_dump($rs);
    }

    public function action_financial_status ($bill_id, $status)
    {
        $financial = new Estimate_Financial($bill_id);
        $financial->set_status($status);
    }

    public function action_site_subdomain($index = -3)
    {
        echo site::subdomain($index);
    }

    public function action_site_domain($type = 'admin')
    {
        echo site::domain($type);
    }


    public function action_user_id ()
    {
        echo user::current_user_id();
    }

    public function action_user_info ()
    {
        echo "<p>current user uid: " . user::current_user_id() . "</p>";
        echo user::current_user_name() . "<br/>";
        echo user::name() ."<br/>";
        print_r(user::current_user_info()) ."<br/>";
        echo "<p>is login: " . user::is_login() . "</p>";
        echo "<p>count(notice): " . user::has_notice() . "</p>";
        echo "<p>current merchant uid: " . user::current_merchant_uid() . "</p>";
    }

    public function action_user_create ()
    {
        $user_info = array(
            'passport' => 'yangxiaoliang2@appchina.com',
            'password' => 'm4eeee',
            'mobile'   => '13401067714',
            'nickname' => 'yangxl',
        );

        $status = 'activated';
        $utype  = 'merchant';

        $uid = user::create($user_info, $status, $utype);
        echo $uid;
    }

    public function action_passport_login ()
    {
        $p = new Passport;
        echo $p->login('yangxiaoliang2@appchina.com', 'm4eeee');
    }

    public function action_passport_logout ()
    {
        $p = new Passport;
        $p->logout();
    }


	public function action_test()
	{
		print_r('this is my test');

	}
}
